package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.dto.SearchDTO;
import com.ruoyi.system.service.ISearchService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.system.service.ISysUserService;

/**
 * 健康咨询Controller
 * 
 * @author saruri
 * @date 2024-08-06
 */
@RestController
@RequestMapping("/search")
public class SearchController extends BaseController {
    @Autowired
    private ISearchService searchService;

    @Autowired
    private ISysUserService userService;


    /**
     * 根据关键词进行分页搜索
     *
     * @param keyword 搜索关键词
     * @return 分页后的搜索结果
     */
    @GetMapping("/list")
    public TableDataInfo search(@RequestParam String keyword) {
        startPage();  // 启动分页，分页参数会从前端传递过来
        List<SearchDTO> searchResults = searchService.searchList(keyword);  // 调用service
        return getDataTable(searchResults);  // 返回分页数据
    }

    /**
     * 随机查询 cover 不为空的数据
     *
     * @return 随机查询结果列表
     */
    @GetMapping("/randomWithCover")
    public TableDataInfo randomSearchWithCover() {
        startPage();  // 启动分页，分页参数会从前端传递过来
        List<SearchDTO> result = searchService.randomSearchWithCover();
        return getDataTable(result);  // 返回分页数据
    }


}